package com.taowan.xunbaozl.morning_speak.design_pattern.day10;

import com.taowan.xunbaozl.morning_speak.design_pattern.day10.ext.CommandExector;
import com.taowan.xunbaozl.morning_speak.design_pattern.day10.ext.Light;
import com.taowan.xunbaozl.morning_speak.design_pattern.day10.ext.LightAllCommand;
import com.taowan.xunbaozl.morning_speak.design_pattern.day10.ext.LightOffCommand;
import com.taowan.xunbaozl.morning_speak.design_pattern.day10.ext.LightOnCommand;

/**
 * Created by 杨观回 on 2016/3/3 0003.
 * 命令模式
 */
public class Test {

    public static void main(String[] args) {

        /**
         *  例子1
         */

        Receiver receiver = new Receiver();

        Command command = new WriteCommand(receiver);

        Invoker invoker = new Invoker(command);

        invoker.action();

        /**
         * 例子2
         */
        Light light = new Light();

        Command command2 = new LightAllCommand(light);

        Invoker invoker2 = new Invoker(command2);

        invoker2.action();

        /**
         * 例子3
         */
        Light light2 = new Light();
        Command command3 = new LightAllCommand(light2);
        Command command4 = new LightOnCommand(light2);
        Command command5 = new LightOffCommand(light2);
        CommandExector commandExector = new CommandExector();
        commandExector.addCommand(command3);
        commandExector.addCommand(command4);
        commandExector.addCommand(command5);
        commandExector.execCommands();
    }
}
